package com.cpecc.dao.wuzi;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import com.cpecc.model.wuzi.CaiGou;
import com.cpecc.model.wuzi.WuZi;

@Repository
public class CaiGouDao {

	@Resource
	private SessionFactory sessionFactory;
	
	public void save(CaiGou caiGou){
		Session session=sessionFactory.getCurrentSession();
		session.save(caiGou);
		session.flush();
	}
	
	public CaiGou get(String id){
		return (CaiGou) sessionFactory.getCurrentSession().get(CaiGou.class, id);
	}
	
	@SuppressWarnings("unchecked")
	public List<CaiGou> list(WuZi wuZi){
		String hql="from CaiGou t where t.wuZi=?";
		Query query=sessionFactory.getCurrentSession().createQuery(hql);
		query.setParameter(0, wuZi);
		return query.list();
	}
	
	public boolean deleteList(WuZi wuZi){
		String hql="delete CaiGou t where t.wuZi=?";
		Query query=sessionFactory.getCurrentSession().createQuery(hql);
		query.setParameter(0, wuZi);
		return query.executeUpdate()>0;
	}
}
